package com.example.secondhandsysapi.Mapper;

import com.example.secondhandsysapi.Entity.NoticeInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NoticeInfoMapper {

    @Select("select * from notice_info")
    List<NoticeInfo> getAllNoticeInfo();

    //首页得到随机的九条公告
    @Select("select * from notice_info where notice_status=1 ORDER BY RAND() LIMIT 9")
    List<NoticeInfo> getRandomNoticeInfo();

    @Select("select * from notice_info where notice_type like '%${type}%'")
    List<NoticeInfo> getInfoByType(@Param("type") String type);

    @Select("select * from notice_info where notice_status=#{status}")
    List<NoticeInfo> getInfoByStatus(@Param("status") Integer status);

    @Select("select * from notice_info where notice_type like '%${type}%' and notice_status=#{status}")
    List<NoticeInfo> getInfoByTypeAndStatus(@Param("type") String type,@Param("status") Integer status);

    @Insert("insert into notice_info(release_person,notice_theme,notice_type,notice_content,notice_image,notice_status) " +
            "values(#{release_person},#{notice_theme},#{notice_type},#{notice_content},#{notice_image},0)")
    Integer addNoticeInfo(NoticeInfo noticeInfo);

    @Update("update notice_info set release_person=#{release_person},notice_theme=#{notice_theme},notice_type=#{notice_type},notice_content=#{notice_content},notice_image=#{notice_image},notice_status=0,release_time=null where notice_id=#{notice_id}")
    Integer updateNoticeInfo(NoticeInfo noticeInfo);

    @Delete("delete from notice_info where notice_id=#{id}")
    Integer deleteNoticeInfo(@Param("id") Integer id);


    //获取公告信息修改后进行审核的内容
    @Select("select notice_id,release_person,notice_type,notice_theme,notice_image,check_info,notice_content from notice_info where notice_status = 0 AND (notice_type = #{notice_type} and notice_theme = #{notice_theme})")
    List<NoticeInfo> getAllNoticeInfo2(@Param("notice_type") String notice_type, @Param("notice_theme") String notice_theme);

    //当给的两个均为空时
    @Select("select notice_id,release_person,notice_type,notice_theme,notice_image,check_info,notice_content from notice_info where notice_status = 0")
    List<NoticeInfo> getAllNoticeInfo1();

    // notice_type不为空，notice_theme为空
    @Select("select notice_id,release_person,notice_type,notice_theme,notice_image,check_info,notice_content from notice_info where notice_status = 0 and notice_type like '%${notice_type}%'")
    List<NoticeInfo> getAllNoticeInfoByType(@Param("notice_type") String notice_type);

    // notice_type为空，notice_theme不为空
    @Select("select notice_id,release_person,notice_type,notice_theme,notice_image,check_info,notice_content from notice_info where notice_status = 0 and notice_theme like '%${notice_theme}%'")
    List<NoticeInfo> getAllNoticeInfoByTheme(@Param("notice_theme") String notice_theme);

    //同意时修改状态
    @Select("UPDATE notice_info SET notice_status = 1 WHERE notice_id = #{notice_id}")
    Integer updateStatus(@Param("notice_id") Integer notice_id);

    //对拒绝填写的备注进行保存
    @Select("UPDATE notice_info SET check_info = #{check_info},notice_status = 2 WHERE notice_id=#{notice_id}")
    Integer updateCheck_Info(@Param("check_info") String check_info,@Param("notice_id") Integer notice_id );

    //公告详情页内容
    @Select("select * from notice_info where notice_id=#{notice_id} and notice_status =1")
    NoticeInfo getNoticeDetailsInfoById(@Param("notice_id") Integer notice_id);
}
